package com.bdqn.service.Impl;

import com.bdqn.dao.Impl.PageQueryDaoImpl;
import com.bdqn.dao.PageQueryDao;
import com.bdqn.entity.CheckWork;
import com.bdqn.entity.Employee;
import com.bdqn.entity.PageBean;
import com.bdqn.service.PageQueryService;



public class PageQueryServiceImpl implements PageQueryService {
    private PageQueryDao dao = new PageQueryDaoImpl();

    @Override
    public PageBean<CheckWork> findByPage(String empId, int currentPage, int pageSize) {
        PageBean<CheckWork> pb = new PageBean<>();
        pb.setCurrentPage(currentPage);
        pb.setPageSize(pageSize);
        int totalCount = dao.findById(empId);
        Employee emp = dao.FindById(empId);
        int depId = emp.getDepId();
        pb.setTotalCount(totalCount);
        int totalPage = totalCount%pageSize==0 ?totalCount/pageSize:(totalCount/pageSize)+1;
        pb.setTotalPage(totalPage);
        int offset = (currentPage-1)*pageSize;
        pb.setList(dao.findByPage(empId,depId,offset,pageSize));
        return pb;
    }

    @Override
    public PageBean<CheckWork> findByPage(String empId, int currentPage, int pageSize, String end, String start) {
        PageBean<CheckWork> pb = new PageBean<>();
        pb.setCurrentPage(currentPage);
        pb.setPageSize(pageSize);
        int totalCount = dao.findById(empId,end,start);
        Employee emp = dao.FindById(empId);
        int depId = emp.getDepId();
        pb.setTotalCount(totalCount);
        int totalPage = totalCount%pageSize==0 ?totalCount/pageSize:(totalCount/pageSize)+1;
        pb.setTotalPage(totalPage);
        int offset = (currentPage-1)*pageSize;
        pb.setList(dao.findByPage(empId,depId,offset,pageSize,end,start));
        return pb;
    }
}
